home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0924.ZIP / BGAME < prev    next >
Text File  |  1988-03-09  |  24KB  |  765 lines

  1.  
  2.  
  3. /* BUSINESS GAME PROGRAM
  4.  
  5.    COMMAND LINE    - EITHER    BGAME OFILE    -I    (period    0 data)
  6.           OR        BGAME DFILE    OFILE -B(alances off) -T(est only).
  7.  
  8.  
  9.    A Business simulation game for between 2 and    5 players or teams.
  10.    Initialise the game (creating the Period 0 data file) by
  11.  
  12.    BGAME DFIL0 -i     - then
  13.    BGAME DFIL0 DFIL1       to produce the equal    start position and
  14.                data    entry file for Period 1.
  15.  
  16.    For each period enter the new market    parameters in the period
  17.    data    file, and the input (area prices, area marketing, production,
  18.    r & d and plant maintenance spends) for each    company, then
  19.  
  20.    BGAME DFILx DFILy     - to run period x and create the next data file.
  21.  
  22.    Reassign stdout to a    file ( >PRN ) to store output for printing.
  23.  
  24.  
  25.    NOTES ON THE    GAME:
  26.    The industry    comprises a 'home' area    for each company (in which the
  27.    'home' company has a    transport cost advantage), and a 'common' area
  28.    in which all    companies compete equally.
  29.  
  30.    Total market    orders depend on prices    quoted,    total marketing    and r &    d,
  31.    and the market parameters set by the    operator.
  32.  
  33.    Company market share    depends    on relative price and marketing, r & d,
  34.    and the market parameters. Marketing    and r &    d spends have effect for
  35.    several periods.
  36.  
  37.    For simplicity, all sales are treated as made for cash.
  38.  
  39.    Company input spend (marketing, production, r & d and plant maintenance)
  40.    should not exceed cash available, but an automatic loan is available
  41.    to ensure that 10000    cash is    always available. Production must be input
  42.    as spend (not volume) and must exceed 7000.
  43.  
  44.    The game should run for at least 5 periods.    Balance    sheets for all
  45.    companies should only be printed every 2, or    4, periods.  Use -b option
  46.    to suppress these.
  47.  
  48.    The winner is the company with the greatest total assets at the end
  49.    of the game.
  50.  
  51.    Have    fun - TJMC.
  52.  
  53. */
  54.  
  55. #include smio.h
  56.  
  57. #define     MINCO          2
  58. #define     MAXCO          5
  59.  
  60. #define     CLS      printf ("\33[2J")
  61.  
  62. /* Global program data */
  63. struct { unsigned
  64.  
  65.      /* previous data */
  66.      cash, plant, stock, stvol, turn, rdeff, loss,
  67.      md2[1 + MAXCO], md1[1+MAXCO],
  68.  
  69.      /* current data */
  70.      price[1 + MAXCO], mark[1 + MAXCO], prod, rnd, pme,
  71.  
  72.      /* derived results */
  73.      demand[1 + MAXCO], sales[1 + MAXCO], tots, totd, totm,
  74.      loan, pcost, pvol, cgs, trs, dep, lint, floss,
  75.      atrn[1    + MAXCO], fplant, ohds,    tax;
  76.  
  77.      float pfc, pvc; int grop, agp[1 + MAXCO],
  78.                  netp, anp[1 + MAXCO], profit, totass;
  79.  
  80.        } cd[MAXCO], *cdp;
  81.  
  82.  
  83. float     pp[5],    atof(),    pscale();
  84.  
  85. unsigned totdmd, admd[1    + MAXCO],
  86.      totsls, asls[1    + MAXCO],
  87.      totmkt, amkt[1    + MAXCO];
  88.  
  89. char     name[85], ind[85];
  90.  
  91. int     prd, coys, pn = sizeof    (pp) / sizeof (float);
  92.  
  93.  
  94. /* Initial equal start data */
  95.  
  96. #define     IPBASE        40
  97. #define     IMBASE        25
  98. #define     IPROD      9050
  99. #define     IRND       200
  100. #define     IPME       120
  101. #define     ICASH     11500
  102. #define     IPLANT      6000
  103. #define     ISTOCK      1650
  104. #define     ISTVOL        50
  105. #define     ITURN     10000
  106. #define     IRDEFF       500
  107. #define     ITLOSS       100
  108.  
  109. int IMTRS  [MAXCO] = { 12, 5, 4, 3, 2 };
  110. int IPTRS  [MAXCO] = {    0, 1, 2, 1, 2 };
  111.  
  112.  
  113. /* Standard data input/output file texts */
  114. char *text1   =    "\nBusiness Game Data.\n",
  115.      *text2   =    "\nGame    title (40 chars):  ",
  116.      *text3   =    "\nIndustry descriptor:       ",
  117.      *text3a  =    "\nNumber of companies:       ",
  118.      *text4   =    "\nNext    period number:       ",
  119.      *text5   =    "\nCompany Data    ",
  120.      *text5a  =    "\n              ",
  121.      *text6   =    "\n\nGame parameters (75 - 200,    100 nominal):\n",
  122.      *text13  =
  123.      "\n\nCompany Input: Prices    (0 or >    30), Marketing ( > 0), ",
  124.      *text14  =
  125.      "\n           Prod ( >    7000), R & D ( < 2000),    PME ( <    2000):",
  126.      *text15  =    "\n\nCompany ",
  127.      *text5b  =    "\n          ",
  128.      *text16  =    "\n\nEnd marker: ",
  129.  
  130.      *ptext[] =    { "\nTotal demand:  ", "\nMarket effect: ",
  131.           "\nPrice effect:  ", "\nR & D    effect:     ",
  132.           "\nProdn base:    "  };
  133.  
  134.  
  135. /* Main    program    - handle files */
  136. main (argc, argv) char *argv[];
  137.  
  138.     {    static int i, j, k, bflag = 0, iflag = 0, tflag    = 0;
  139.     static FILE *df, *of; FILE * fopen();
  140.     static char c, *p, s[45], *dfil    = NULL,    *ofil =    NULL;
  141.  
  142.     /* Read    command    line */
  143.     while (--argc)
  144.     {  if (**++argv    == '-')
  145.        { p = *argv;    while (c = toupper (*++p))
  146.          {    if (c == 'B') bflag = 1;
  147.         if (c == 'T') tflag = 1;
  148.         if (c == 'I') iflag = 1; } }
  149.        else    if (dfil == NULL) dfil = *argv;
  150.        else    ofil = *argv; }
  151.  
  152.     if (iflag == 0)    /* normal run */
  153.  
  154.     {  if (dfil == NULL)
  155.        {  printf ("\nNo data file specified.\n"); return; }
  156.  
  157.        if ((df = fopen (dfil, "r"))    == NULL)
  158.        {  printf ("\nCannot    open data file %s\n", dfil); return; }
  159.  
  160.        k = getdata (df); fclose (df);
  161.  
  162.        switch (k)
  163.        {  case 1:  printf ("\nData format error.\n"); return;
  164.           case 2:  p = "Parameter";     goto exr;
  165.           case 4:  p = "Price";     goto exr;
  166.           case 5:  p = "Marketing";     goto exr;
  167.           case 6:  p = "Production"; goto exr;
  168.           case 7:  p = "R &    D";     goto exr;
  169.           case 8:  p = "Plant mtce";
  170.         exr :  printf ("\n%s out of range.\n", p); return;
  171.           case 9:  printf ("\nSpend    exceeds    cash.\n"); return; }
  172.  
  173.        setdemand ();
  174.  
  175.        for (i = 0; i < coys; ++i) coyresults (i);
  176.  
  177.        for (j = totdmd = totsls = totmkt = 0; j <= coys; ++j)
  178.        {  for (i = admd[j] = asls[j] = amkt[j] = 0,    cdp = cd;
  179.            i < coys; ++i, ++cdp)
  180.           {     admd[j] += cdp->demand[j];
  181.          asls[j] += cdp->sales[j];
  182.          amkt[j] += cdp->mark[j];  }
  183.           totdmd +=    admd[j];
  184.           totsls +=    asls[j];
  185.           totmkt +=    amkt[j];  }
  186.  
  187.        if (!tflag) for (i =    0; i < coys; ++i) coyprint (i, bflag);
  188.  
  189.        else    { summary (); return; }
  190.  
  191.     }
  192.  
  193.     else /*    initialisation run */
  194.  
  195.     {  CLS;
  196.        printf ("\nEnter Game title (40 chars): "); gets (name);
  197.        printf ("\nEnter Industry descriptor:   "); gets (ind);
  198.        do {     printf    ("\nEnter Number of Companies:     ");
  199.          scanf ("%d", &coys); }
  200.        while (coys < MINCO || coys > MAXCO);
  201.        for (i = 0; i < pn; ++i) pp[i] = 100.;
  202.        ofil    = dfil;    }
  203.  
  204.     if (ofil == NULL)
  205.     {  printf ("\n\nNo output file specified.\n"); return; }
  206.  
  207.     if ((of    = fopen    (ofil, "w")) ==    NULL)
  208.     {  printf ("\n\nCannot open output file    %s\n", ofil); return; }
  209.  
  210.     outdata    (of, iflag);
  211.     if (fclose (of)    == -1)
  212.     printf ("\n\nCannot close output file %s\n", ofil);
  213.  
  214.     } /* End of    main */
  215.  
  216.  
  217. /* Input the data file in standard format */
  218. getdata    (df) FILE *df;
  219.     {    static int i, j, k, tm;    static char c, s[45]; static float f;
  220.  
  221.     fscanf (df, text1); fscanf (df,    text2);
  222.     c = getc (df);
  223.     while (c == ' '    || c ==    '\t') c    = getc (df);
  224.     for (i = 0; i <    40; ++i)
  225.     {  if (c == '\r' || c == '\n') break;
  226.        name[i] = c;    c = getc (df); }
  227.     while (c != '\r' && c != '\n') c = getc    (df);
  228.  
  229.     fscanf (df, text3);  fscanf (df, "%s", ind);
  230.     fscanf (df, text3a); fscanf (df, "%d", &coys);
  231.     fscanf (df, text4);  fscanf (df, "%d", &prd);
  232.  
  233.     for (i = 0, cdp    = cd; i    < coys;    ++i, ++cdp)
  234.     {  fscanf (df, text5); fscanf (df, "%d:", &j);
  235.        if (i != --j) return    1;
  236.        fscanf (df, "%d,%d,%d,%d,%d,%d,%d",
  237.          &(cdp->cash),    &(cdp->plant), &(cdp->stock),
  238.          &(cdp->stvol),    &(cdp->turn),  &(cdp->rdeff), &(cdp->loss));
  239.        for (j = 0; j <= coys; ++j)
  240.        fscanf (df, ",%d", &(cdp->md2[j]));
  241.        for (j = 0; j <= coys; ++j)
  242.        fscanf (df, ",%d", &(cdp->md1[j])); }
  243.  
  244.     fscanf (df, text6);
  245.     for (i = 0; i <    pn; ++i)
  246.     {  fscanf (df, ptext[i]); fscanf (df, "%30s", s);
  247.        if ((f = pp[i] = atof(s)) < 74.99 ||    f > 200.01) return 2; }
  248.  
  249.     fscanf (df, text13); fscanf (df, text14);
  250.     for (i = 0, cdp    = cd; i    < coys;    ++i, ++cdp)
  251.     {  fscanf (df, text15);    fscanf (df, "%d:", &j);
  252.        if (i != --j) return    1;
  253.        tm =    0;
  254.        for (j = 0; j <= coys; ++j)
  255.        {  fscanf (df, "%d,", &(cdp->price[j]));
  256.           k    = cdp->price[j];
  257.           if (k && (k < 30 || k > 499)) return 4; }
  258.        for (j = 0; j <= coys; ++j)
  259.        {  fscanf (df, "%d,", &(cdp->mark[j]));
  260.           tm += (k = cdp->mark[j]);
  261.           if (k < 0) return    5; }
  262.        fscanf (df, "%d,%d,%d",
  263.            &(cdp->prod), &(cdp->rnd), &(cdp->pme));
  264.        if (cdp->prod  < 7000) return 6;
  265.        if (cdp->rnd    < 0 || cdp->rnd    > 2000 ) return    7;
  266.        if (cdp->pme    < 0 || cdp->pme    > 2000 ) return    8;
  267.        k = tm + cdp->prod +    cdp->rnd + cdp->pme;
  268.        if (k > 10000 && k >    cdp->cash) return 9; }
  269.  
  270.     fscanf (df, text16); k = fscanf    (df, "%x", &j);
  271.     return (k == 0 || j != -1) ? 1 : 0;
  272.  
  273.     } /* End of    getdata    */
  274.  
  275.  
  276. /* Evaluate area/company demand    */
  277. setdemand ()
  278.      {    static float s,    x, dd, mm, tr, tp, tm, nc, pm, aft,
  279.              mef[MAXCO], aff[MAXCO], rde[MAXCO], rdf[MAXCO];
  280.     static int i, j, k;
  281.  
  282.     for (i = 0, cdp    = cd, tr = 0.; i < coys; ++i, ++cdp)
  283.     {  tr += (rde[i] = ((float) cdp->rdeff * .6 + (float) cdp->rnd));
  284.        if ((x = (float) cdp->turn) < 4000.)    x = 4000.;
  285.        rdf[i] = 1. + 3. * rde[i] / x; }
  286.  
  287.     for (j = 0; j <= coys; ++j)
  288.     {  pm =    1000.; tp = tm = 1.; nc    = 0.;
  289.        for (i = 0, cdp = cd; i < coys; ++i,    ++cdp)
  290.        {  mef[i] = (((float) cdp->md2[j] + (float) cdp->md1[j]) / 2.
  291.                + (float) cdp->mark[j]) / 2.;
  292.           tp += (float) (k = cdp->price[j]); tm += mef[i];
  293.           x    = (float) k + 200. / (1. + mef[i]);
  294.           if (k) nc    += 1.; if (k &&    x < pm)    pm = x;    }
  295.  
  296.        s = 3. * (15. + nc) * (mm = (j < coys) ? 1.0    : 2.125);
  297.        if (tm < (125. * mm)) x = tm    / (125.    * mm);
  298.        else    x = 3. - (250. * mm) / tm;
  299.        dd =    .44 * s    * pp[0]    * (1. +    tr/50000.) * x / pm;
  300.        if (nc > 0) { tp /= nc; tm /= nc; }
  301.  
  302.        for (i = 0, cdp = cd, aft = 0.; i < coys; ++i, ++cdp)
  303.        {  x    = cdp->price[j]    ?
  304.          (rdf[i] * (mef[i] / tm    - pscale (pp[1], .00, .15)) *
  305.          (tp / (float) cdp->price[j] -
  306.             pscale (pp[2], .76, .85))) : 0.;
  307.           aft += (aff[i] = (x > 0.)    ? x : 0.); }
  308.  
  309.        for (i = 0, cdp = cd; i < coys; ++i,    ++cdp)
  310.        cdp->demand[j] = (aft > 0.) ? (int) (dd * aff[i] / aft) : 0;
  311.     }
  312.     } /* End of    setdemand */
  313.  
  314.  
  315. /* Evaluate company results and    set output values */
  316. coyresults (i)
  317.      {    static float x,    y, pdf;    static int j, k, as, tg, tn;
  318.  
  319.     cdp = cd + i;
  320.     x = (float) cdp->rdeff * .6 + (float) cdp->rnd;
  321.     pdf = 1. - pscale (pp[3], .50, .65) * x    /100000.;
  322.     if (pdf    < .93) pdf = .93;
  323.     cdp->rdeff = (int) x;
  324.     cdp->pfc = 2.  * ((float) cdp->plant / 20.) +
  325.            pdf * (x = pscale (pp[4], 27., 37.))    * 50.;
  326.     cdp->pvc = pdf * x - 2.;
  327.  
  328.     cdp->pvol = ((float) cdp->prod - cdp->pfc) / cdp->pvc;
  329.     if (((float) cdp->pvol * cdp->pvc + cdp->pfc)
  330.           >    cdp->prod) --(cdp->pvol);
  331.     cdp->pcost = (float) cdp->pvol * cdp->pvc + cdp->pfc;
  332.     as = cdp->pvol + cdp->stvol;
  333.  
  334.     for (j = cdp->totd = cdp->totm = 0; j <= coys; ++j)
  335.     {  cdp->totd +=    cdp->demand[j];
  336.        cdp->totm +=    cdp->mark[j];
  337.        cdp->md2[j] = cdp->md1[j];
  338.        cdp->md1[j] = cdp->mark[j]; }
  339.  
  340.     if ((x = (float) as / (float) cdp->totd) > 1.) x = 1.;
  341.     for (j = k = 0;    j <= coys; ++j)
  342.     k += (cdp->sales[j] = (float) cdp->demand[j] * x);
  343.     if (k >    as) cdp->sales[coys] -=    (k - as);
  344.     if (as < cdp->totd && k    < as) cdp->sales[coys] += (as -    k);
  345.  
  346.     for (j = cdp->tots = 0;    j <= coys; ++j)
  347.     cdp->tots += cdp->sales[j];
  348.  
  349.     for (j = cdp->trs = cdp->turn =    0; j <=    coys; ++j)
  350.     {  cdp->turn +=    (cdp->atrn[j] =    cdp->sales[j] *    cdp->price[j]);
  351.        if (j == i) k = 0;
  352.        else    if (j == coys) k = 1;
  353.        else    k = 2;
  354.        cdp->trs += (cdp->sales[j] *    k); }
  355.  
  356.     if (cdp->tots <= cdp->stvol)
  357.        cdp->cgs = (float) cdp->tots    *
  358.               (float) cdp->stock / (float) cdp->stvol;
  359.     else
  360.        cdp->cgs = (float) cdp->stock +
  361.               (float) (cdp->tots - cdp->stvol) *
  362.               (float) cdp->pcost / (float) cdp->pvol;
  363.  
  364.     cdp->stock += (cdp->pcost - cdp->cgs);
  365.     cdp->stvol += (cdp->pvol  - cdp->tots);
  366.  
  367.     cdp->dep  = cdp->plant / 50;
  368.     k = cdp->totm +    cdp->pcost + cdp->rnd +    cdp->pme;
  369.     cdp->loan = (k > cdp->cash) ? (k - cdp->cash) :    0;
  370.     cdp->lint = cdp->loan /    25;
  371.  
  372.     cdp->grop = cdp->turn -    cdp->cgs  - cdp->trs;
  373.     cdp->ohds = cdp->rnd  +    cdp->lint + cdp->dep;
  374.     cdp->netp = k =    cdp->grop - cdp->totm -    cdp->ohds;
  375.     cdp->floss = cdp->loss;    cdp->fplant = cdp->plant;
  376.     cdp->tax  = (k < (int) cdp->loss) ? 0 :    (k - cdp->loss)    / 2;
  377.     cdp->loss = (k < (int) cdp->loss) ? cdp->loss -    k : 0;
  378.     cdp->profit = k    - cdp->tax;
  379.  
  380.     x = (float) cdp->cgs  /    (float)    cdp->tots;
  381.     y = (float) cdp->ohds /    (float)    cdp->tots;
  382.     for (j = tg = tn = 0; j    <= coys; ++j)
  383.     {  if (j == i) k = 0;
  384.        else    if (j == coys) k = 1;
  385.        else    k = 2;
  386.        tg += (cdp->agp[j] =    (float)    cdp->sales[j] *
  387.                    ((float)    cdp->price[j] -    x - (float) k));
  388.        tn += (cdp->anp[j] =    (float)    cdp->agp[j]
  389.                   -    (float)    cdp->mark[j]
  390.                   -    (float)    cdp->sales[j] *    y); }
  391.     if (tg != cdp->grop) cdp->agp[coys] += (cdp->grop - tg);
  392.     if (tn != cdp->netp) cdp->anp[coys] += (cdp->netp - tn);
  393.  
  394.     cdp->plant += (cdp->pme    - cdp->dep);
  395.     cdp->cash  += (cdp->turn - cdp->pcost -    cdp->totm  - cdp->rnd -
  396.                cdp->pme     - cdp->trs - cdp->tax);
  397.     cdp->totass = cdp->plant + cdp->stock +    cdp->cash;
  398.  
  399.     } /* End of    coyresults */
  400.  
  401.  
  402. /* Display company results */
  403. coyprint (c, bs)
  404.      {    static int i, j, k, gp;    static float x;
  405.  
  406.     printf ("\n%-42.30s", name);
  407.     printf ("INDUSTRY %c  COMPANY %d  PERIOD %2d\n",
  408.          *ind, c + 1, prd);
  409.  
  410.     printf ("\nINDUSTRY MARKET INFORMATION:");
  411.     printf ("\n\n             ");
  412.     for (j = MAXCO;    j > coys; --j) printf ("    ");
  413.     for (j = 0; j <= coys; ++j) printf ("Area %d   ", j + 1);
  414.     printf ("Total");
  415.  
  416.     printf ("\nPRICES:");
  417.     for (i = 0, cdp    = cd; i    < coys;    ++i, ++cdp)
  418.     {  printf ("\nCompany %d:    ",    i + 1);
  419.        for (j = MAXCO; j > coys; --j) printf ("    ");
  420.        for (j = 0; j <= coys; ++j)
  421.        printf ("%6d      ", cdp->price[j]); }
  422.     printf ("\n");
  423.  
  424.     cdp = cd + c;
  425.     linrep ("\nOrders (000's)", admd, totdmd);
  426.     linrep ("\nSales     ", asls, totsls);
  427.     linrep ("\nMarketing     ", amkt, totmkt);
  428.  
  429.     printf ("\n\nCOMPANY MARKET INFORMATION:\n");
  430.     linrep ("\nOrders (000's)", cdp->demand, cdp->totd);
  431.     linrep ("\nSales     ", cdp->sales,     cdp->tots);
  432.     linrep ("\nTurnover     ", cdp->atrn,     cdp->turn);
  433.     linrep ("\nMarketing     ", cdp->mark,     cdp->totm);
  434.     linrep ("\nGross profit     ", cdp->agp,     cdp->grop);
  435.     linrep ("\nNet profit     ", cdp->anp,     cdp->netp);
  436.     printf ("\n");
  437.  
  438.     printf ("\nPROFIT & LOSS STATEMENT:  ");
  439.     printf ("      PRODUCTION REPORT:\n");
  440.  
  441.     printf ("\nTurnover (000's)    %8d", cdp->turn);
  442.     printf ("             Quantity  Cost       Unit");
  443.     printf ("\nLess:               ");
  444.     printf ("              (000's) (000's)");
  445.     printf ("\nCost    of goods sold  %8d", -cdp->cgs);
  446.     printf ("    If 10%%    under       %5d%8d%8.2f",
  447.         k = cdp->pvol -    cdp->pvol / 10,
  448.         (int) (x = (float) k * cdp->pvc    + cdp->pfc),
  449.         x / (float) k);
  450.     printf ("\nTransport costs     %8d", -cdp->trs);
  451.     printf ("    Current    production%5d%8d%8.2f",
  452.            cdp->pvol, cdp->pcost,
  453.            (float) cdp->pcost / (float) cdp->pvol);
  454.     printf ("\n             ------");
  455.         k = cdp->pvol +    cdp->pvol / 10;
  456.         if (k >    (cdp->fplant / 20)) k =    cdp->fplant / 20;
  457.     printf ("    If 10%%    over       %5d%8d%8.2f",
  458.         k,
  459.         (int) (x = (float) k * cdp->pvc    + cdp->pfc),
  460.         x / (float) k);
  461.     printf ("\nGross profit           %8d", gp    = cdp->grop);
  462.     printf ("    At new capacity      %5d%8d%8.2f",
  463.         k = cdp->plant / 20,
  464.         (int) (x = (float) k * cdp->pvc    + cdp->pfc),
  465.         x / (float) k);
  466.     printf ("\nLess:               ");
  467.     printf ("    Closing    stock      %5d%8d%8.2f",
  468.            cdp->stvol, cdp->stock,
  469.            (float) cdp->stock / (float) cdp->stvol);
  470.  
  471.     printf ("\nMarketing costs     %8d", -cdp->totm);
  472.     printf ("\nResearch & dev      %8d", -cdp->rnd);
  473.     printf ("\nDepreciation           %8d", -cdp->dep);
  474.     printf ("    STATEMENT OF ASSETS:");
  475.     printf ("\nInterest (on     %5d)%8d", cdp->loan, -cdp->lint);
  476.     printf ("\n             ------");
  477.     printf ("    Plant (000's)         %8d", cdp->plant);
  478.     printf ("\nNet profit           %8d", cdp->netp);
  479.     printf ("    Stock             %8d", cdp->stock);
  480.     printf ("\nTax (loss b/f %5d)%8d", cdp->floss, -cdp->tax);
  481.     printf ("    Cash             %8d", cdp->cash);
  482.     printf ("\n             ------");
  483.     printf ("                   ------");
  484.     printf ("\nProfit           %8d", cdp->profit);
  485.     printf ("    Total assets         %8d", cdp->totass);
  486.     printf ("\n             ======");
  487.     printf ("                   ======");
  488.     printf ("\n");
  489.  
  490.     if (!bs)
  491.     {  printf ("\nPUBLISHED    ASSETS:     ");
  492.        for (i = 0; i < coys; ++i)
  493.        printf ("    Coy %d ", i + 1);
  494.        printf ("\n");
  495.  
  496.        printf ("\nPlant (000's)    ");
  497.        for (i = 0, cdp = cd; i < coys; ++i,    ++cdp)
  498.        printf ("%10d", cdp->plant);
  499.  
  500.        printf ("\nStock        ");
  501.        for (i = 0, cdp = cd; i < coys; ++i,    ++cdp)
  502.        printf ("%10d", cdp->stock);
  503.  
  504.        printf ("\nCash        ");
  505.        for (i = 0, cdp = cd; i < coys; ++i,    ++cdp)
  506.        printf ("%10d", cdp->cash);
  507.  
  508.        printf ("\n            ");
  509.        for (i = 0; i < coys; ++i) printf ("       ------");
  510.  
  511.        printf ("\nTotal assets    ");
  512.        for (i = 0, cdp = cd; i < coys; ++i,    ++cdp)
  513.        printf ("%10d", cdp->totass);
  514.  
  515.        printf ("\n            ");
  516.        for (i = 0; i < coys; ++i) printf ("       ======");
  517.  
  518.        printf ("\n"); }
  519.  
  520.      else printf ("\n\n\n\n\n\n\n\n\n");
  521.  
  522.       printf ("\n\n\n"); /* SPACERS - REPORT IS    54 LINES */
  523.  
  524.     } /* End of    coyprint */
  525.  
  526.  
  527. /* Print area analysis line */
  528. linrep (ss, aa,    tt) char *ss; unsigned aa[], tt;
  529.      {    static int j;
  530.     printf (ss);
  531.     for (j = MAXCO;    j > coys; --j) printf ("    ");
  532.     for (j = 0; j <= coys; ++j) printf ("%6d   ", aa[j]);
  533.     printf ("%6d", tt); }
  534.  
  535.  
  536. /* Print area/company demand */
  537. summary()
  538.      {    static int i, j, tt;
  539.  
  540.     printf ("\nCONFIDENTIAL    - OPERATOR SUMMARY.");
  541.  
  542.     printf ("\nMARKETING:           ");
  543.     for (i = MINCO;    i < coys; ++i) printf ("      ");
  544.     printf ("TOTAL      PRICES:");
  545.     for (i = 0, cdp    = cd; i    < coys;    ++i, ++cdp)
  546.     {  printf ("\nC    %d:", i    + 1);
  547.        for (j = 0; j <= coys; ++j)
  548.        printf ("%6d", cdp->mark[j]);
  549.        printf ("%6d", cdp->totm);
  550.        printf ("   ");
  551.        for (j = 0; j <= coys; ++j)
  552.        printf ("%4d", cdp->price[j]); }
  553.     printf ("\n");
  554.  
  555.     printf ("\nDEMAND:           ");
  556.     for (i = MINCO;    i < coys; ++i) printf ("      ");
  557.     printf ("TOTAL    SALES  PROD   STOCK");
  558.     for (i = 0, cdp    = cd; i    < coys;    ++i, ++cdp)
  559.     {  printf ("\nC    %d:", i    + 1);
  560.        for (j = tt = 0; j <= coys; ++j)
  561.        printf ("%6d", cdp->demand[j]);
  562.        printf ("%6d", cdp->totd);
  563.        printf ("%7d", cdp->tots);
  564.        printf ("%7d", cdp->pvol);
  565.        printf ("%7d", cdp->stvol); }
  566.  
  567.     printf ("\n    --------------------------------");
  568.     for (i = MINCO;    i < coys; ++i) printf ("------");
  569.     printf ("\n    ");
  570.     for (j = 0; j <= coys; ++j)
  571.     printf ("%6d", admd[j]);
  572.     printf ("%6d", totdmd);
  573.     printf ("%7d", totsls);
  574.     printf ("\n");
  575.  
  576.     printf ("\nNET PROFIT:           ");
  577.     for (i = MINCO;    i < coys; ++i) printf ("      ");
  578.     printf ("TOTAL    PLANT  STOCK  CASH  TOTAL");
  579.     for (i = 0, cdp    = cd; i    < coys;    ++i, ++cdp)
  580.     {  printf ("\nC    %d:", i    + 1);
  581.        for (j = tt = 0; j <= coys; ++j)
  582.        printf ("%6d", cdp->anp[j]);
  583.        printf ("%6d", cdp->netp);
  584.        printf ("%7d", cdp->plant);
  585.        printf ("%7d", cdp->stock);
  586.        printf ("%7d", cdp->cash);
  587.        printf ("%7d", cdp->plant + cdp->stock +
  588.               cdp->cash); }
  589.     printf ("\n");
  590.  
  591.        } /* End    of prdem */
  592.  
  593.  
  594. /* Scale parameters from nominal 75 - 200 range    */
  595. float pscale (p, x, y) float p,    x, y;
  596.     {    return x + (p -    75.) / 125. * (y - x); }
  597.  
  598.  
  599. /* Output the next data    template in standard format */
  600. outdata    (of, ff) FILE *of;
  601.     {    static int i, j, k; static char    c, s[40];
  602.  
  603.     fprintf    (of, "%s", text1);
  604.     fprintf    (of, "%s%-40s",    text2,    name);
  605.     fprintf    (of, "%s%c", text3,  *ind);
  606.     fprintf    (of, "%s%d", text3a, coys);
  607.     fprintf    (of, "%s%d\n", text4,
  608.              ff    ? 0 : prd + 1);
  609.  
  610.     for (i = 0, cdp    = cd; i    < coys;    ++i, ++cdp)
  611.     {  fprintf (of,    "%s%d:", text5,    i + 1);
  612.        fprintf (of,    " %d, %d, %d, %d, %d, %d, %d,",
  613.             ff ? ICASH    : cdp->cash,
  614.             ff ? IPLANT    : cdp->plant,
  615.             ff ? ISTOCK    : cdp->stock,
  616.             ff ? ISTVOL    : cdp->stvol,
  617.             ff ? ITURN    : cdp->turn,
  618.             ff ? IRDEFF    : cdp->rdeff,
  619.             ff ? ITLOSS    : cdp->loss);
  620.  
  621.        fprintf (of,    "%s", text5a);
  622.        for (j = 0; j < coys; ++j)
  623.        fprintf (of,    "%d, ",
  624.             ff ? IMBASE    * IMTRS    [(5 * coys + i - j) % coys]
  625.                : cdp->md2[j]);
  626.        fprintf (of,    "%d, ",
  627.             ff ? IMBASE    * IMTRS    [0] : cdp->md2[coys]);
  628.        fprintf (of,    "%s", text5a);
  629.        for (j = 0; j < coys; ++j)
  630.        fprintf (of,    "%d, ",
  631.             ff ? IMBASE    * IMTRS    [(5 * coys + i - j) % coys]
  632.                : cdp->md1[j]);
  633.        fprintf (of,    "%d",
  634.             ff ? IMBASE    * IMTRS    [0] : cdp->md1[coys]); }
  635.  
  636.     fprintf    (of, "%s", text6);
  637.     for (i = 0; i <    pn; ++i)
  638.     {  fprintf (of,    "%s", ptext[i]);
  639.        fprintf (of,    "%8.1f", pp[i]); }
  640.  
  641.     fprintf    (of, "%s", text13); fprintf (of, "%s", text14);
  642.  
  643.     for (i = 0; i <    coys; ++i)
  644.     {  fprintf (of,    "%s%d: ", text15, i + 1);
  645.        if (ff)
  646.        {  for (j = 0; j < coys; ++j)
  647.           fprintf (of, "%d,    ", IPBASE +
  648.                    IPTRS [(5 * coys - i    + j) % coys]);
  649.           fprintf (of, "%d,    ", IPBASE + 1);
  650.           fprintf (of, "%s", text5b);
  651.           for (j = 0; j < coys; ++j)
  652.           fprintf (of, "%d,    ", IMBASE *
  653.                    IMTRS [(5 * coys + i    - j) % coys]);
  654.           fprintf (of, "%d,    ", IMBASE * IMTRS [0]);
  655.           fprintf (of, "%s", text5b);
  656.           fprintf (of, "%d,    ", IPROD);
  657.           fprintf (of, "%d,    ", IRND);
  658.           fprintf (of, "%d ",  IPME); }
  659.        else    fprintf    (of, "\n\n"); }
  660.  
  661.     fprintf    (of, "%s%s", text16, "FFFF\n\n");
  662.  
  663.     } /* End of    outdata    */
  664.  
  665.  
  666. #list-
  667.  
  668. /* SCANF/FSCANF/SSCANF FUNCTIONS - 16 BIT INPUT    ONLY */
  669.  
  670. scanf (fs) int *fs;
  671.      { int getc(), ungetc(); return _ffin (stdin, fs, getc, ungetc); }
  672. fscanf (fs) int    *fs;
  673.      { int getc(), ungetc(); return _ffin(*fs,    --fs, getc, ungetc); }
  674. sscanf (fs) int    *fs;
  675.      { int _mgt(), _mungt(); return _ffin(fs,    --fs, _mgt, _mungt); }
  676.  
  677. _ffin (fp, pp, read, ungetc)
  678.   char *fp, **pp; int (*read)(), (*ungetc)();
  679.      {    static int bb, base, value, asflag, sflag,
  680.            ch, temp, i,    count, width;
  681.     static char *ff, c; int    _ffgd();
  682.  
  683.     ff = *pp--; count = 0;
  684.     while (c = *ff++)
  685.     {   if (isspace    (c)) continue;
  686.         if (c != '%')
  687.         {    while (isspace (ch = (*read) (fp)));
  688.         if (ch == c) continue;
  689.         else return (ch    == EOF)    ? EOF :    count; }
  690.         sflag = asflag = 0;
  691.         if ((*ff) == '*') {    ++asflag; ++ff;    }
  692.         width = isdigit (*ff) ? 0 :    -1;
  693.         if (width == 0)
  694.         {    while ((c = *ff) >= '0'    && c <=    '9')
  695.         {  width = width * 10 +    (c - '0'); ++ff; } }
  696.  
  697.         switch ( toupper (c    = *ff++))
  698.         {  case 'D':
  699.            case 'U': base =    10; goto decode;
  700.            case 'O': base =    8;  goto decode;
  701.            case 'X': base =    16;
  702.            decode:
  703.          bb = 0; while (isspace    (ch = (*read) (fp)));
  704.          if (ch    == EOF)    return EOF;
  705.          if (width && (ch == '+' || ch == '-'))
  706.          {  if (ch == '-') ++sflag;
  707.             ch = (*read) (fp); --width;    }
  708.          if (width && base == 16 && ch == '0')
  709.          {  temp = (*read) (fp); --width;
  710.             if (toupper    (temp) == 'X' && width)
  711.             {  ch = (*read) (fp); --width; }
  712.             else
  713.             {  (*ungetc) (temp,    fp); ++width; }    }
  714.          if ((value = _ffgd(ch,    base)) == -1) return count;
  715.          while (width && (value    != -1))
  716.          {  bb = bb * base + value;
  717.             ch = (*read) (fp); --width;
  718.             value = _ffgd (ch, base); }
  719.          (*ungetc) (ch,    fp);
  720.          if (sflag) bb = - bb;
  721.          if (!asflag) {    * (int *) (*pp)    = bb; ++count; --pp; }
  722.          break;
  723.  
  724.            case 'S':
  725.          while (isspace    (ch = (*read) (fp)));
  726.          if (ch    == EOF)    return EOF;
  727.          while (width && ch != ' ' && ch != '\t' && ch != '\r'
  728.             && ch != '\n' && ch != EOF)
  729.          {  if (!asflag) *(*pp)++ = ch;
  730.             ch = (*read) (fp); --width;    }
  731.          (*ungetc) (ch,    fp);
  732.          if (!asflag)
  733.          {  *(*pp) = '\0'; ++count; --pp; }
  734.          break;
  735.  
  736.            case 'C':
  737.          if ((ch = (*read) (fp)) == EOF) return    EOF;
  738.          else if (!asflag) { *(*pp) = ch; ++count; --pp; }
  739.          break;
  740.  
  741.            default:    return count;
  742.        } }
  743.  
  744.        return count;
  745.  
  746.     } /* End of _ffin */
  747.  
  748.  
  749. /* Utilities for scanf and sscanf */
  750.  
  751. _ffgd (ch, base)
  752.      {     if (ch    >= '0' && ch <=    '9') ch    -= '0';
  753.      else if (isalpha (ch =    toupper    (ch))) ch -= ('A' - 10);
  754.      else  return -1;
  755.      return    (ch < base) ? ch : -1; }
  756.  
  757. _mgt (s) char **s; {  return (*(*s) != '\0') ? *(*s)++ : EOF; }
  758.  
  759. _mungt (c, s) int c; char **s; { --(*s);  return c; }
  760.  
  761.  
  762. #include ?smfps.lib?
  763. #include ?smio.lib?
  764.  
  765.